﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics.ClientDisplayMechanics {
    import flash.events.*;
    import flash.geom.*;
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import Classes.*;
    import Classes.effects.*;
    import validation.*;

    public class EffectRenderer implements IMapResourceEffectMechanic, IValidationMechanic {

        protected var m_owner:MechanicMapResource;
        protected var m_type:String;
        protected var m_effectType:String;
        protected var m_validation:GenericValidationScript;
        protected var m_effect:MapResourceEffect;

        public function updateDisplayObject(_arg1:Number):void{
            if (this.isValid()){
                if (this.m_effect){
                    this.updateEffect(_arg1);
                } else {
                    this.initEffect();
                };
            } else {
                if (this.m_effect){
                    this.killEffect();
                };
            };
        }
        public function isPixelInside(_arg1:Point):Boolean{
            return (false);
        }
        public function initialize(_arg1:IMechanicUser, _arg2:MechanicConfigData):void{
            this.m_owner = (_arg1 as MechanicMapResource);
            this.m_type = _arg2.params["type"];
            this.m_effectType = _arg2.params["effectType"];
            this.m_validation = this.m_owner.getItem().getValidation(_arg2.params["validate"]);
        }
        public function isVisitEnabled():Boolean{
            return (false);
        }
        public function isValid():Boolean{
            return ((this.m_validation) ? this.m_validation.validate(this.m_owner) : true);
        }
        public function initEffect():void{
            this.m_effect = MapResourceEffectFactory.createEffect(this.m_owner, this.getEffectType());
            this.m_owner.addEventListener(MapResource.REPLACE_CONTENT, this.onReplaceContent);
        }
        public function updateEffect(_arg1:Number):void{
        }
        public function killEffect():void{
            this.m_owner.removeEventListener(MapResource.REPLACE_CONTENT, this.onReplaceContent);
            this.m_effect.cleanUp();
            this.m_effect = null;
        }
        final protected function getEffectType():EffectType{
            if (this.hasOwnProperty("effectOverride")){
                return ((this["effectOverride"] as EffectType));
            };
            return (EffectType[this.m_effectType.toUpperCase()]);
        }
        protected function onReplaceContent(_arg1:Event=null):void{
            this.m_effect.reattach();
        }

    }
}//package Mechanics.ClientDisplayMechanics 
